﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SHJunketingBLL;
using SHJunketingModel;

public partial class Admin_UserManagement_CheckPassWord : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        if (Session["userLogin"] != null) 
        {
            C_UserLogin c_userLogin = Session["userLogin"] as C_UserLogin;
            string pass = this.txtPass.Text.Trim();  //原密码
            C_UserLogin userLogin = C_UserLoginManager.GetUserLogin(c_userLogin.UserName, GetPassWord(pass));
            if (userLogin != null)
            {
                string pwd = this.txtPwd.Text.Trim();
                string pwd1 = this.txtPwd1.Text.Trim();
                if (pwd.Equals(pwd1))
                {
                    C_UserLogin login = new C_UserLogin();
                    login.UserId = c_userLogin.UserId;
                    login.UserName = c_userLogin.UserName;
                    login.UserPwd = GetPassWord(pwd);
                    C_UserLoginManager.ModifyC_UserLogin(login);
                    Response.Redirect("CheckOK.aspx");
                }
                else 
                {
                    Web.CommFun.Show_Msg("两次密码输入不一致，请再次输入", "CheckPassWord.aspx");
                }
            }
            else //原密码输入错误
            {
                Web.CommFun.Show_Msg("原密码输入错误，请再次输入", "CheckPassWord.aspx");
            }

        }
    }


    //密码加密
    public string GetPassWord(string pass) 
    {
        string pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pass, "MD5");
        for (int a = 0; a < pass.Length; a++)
        {
            pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5");
        }
        return pwd;
    }
}
